/**
 * 
 */
package systole.domain.persons;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;

import systole.domain.persons.identityCard.IdentityCard;

/**
 * @author juan
 * 
 */
public abstract class Person implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = -8529946472166783008L;
    protected Integer id;
    protected String name;
    protected String surname;
    protected String address;
    protected String telephone;
    protected String cellphone;
    protected String email;
    protected Date birthdate;
    protected String city;
    protected String sex;
    protected String note;
    protected IdentityCard identityCard;
    protected AgeUtils ageUtils;
    protected Calendar lastUpdate;

    /**
     * Empty constructor.
     */
    public Person() {
        super();
        this.ageUtils = new AgeUtils();
    }

    /**
     * @return the name
     */
    public String getName() {
        return this.name;
    }

    /**
     * @param name
     *            the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the surname
     */
    public String getSurname() {
        return this.surname;
    }

    /**
     * @param surname
     *            the surname to set
     */
    public void setSurname(String surname) {
        this.surname = surname;
    }

    /**
     * @return The surname and name.
     */
    public String getFullName() {
        return this.getSurname() + ", " + this.getName();
    }

    /**
     * @return the address
     */
    public String getAddress() {
        return this.address;
    }

    /**
     * @param address
     *            the address to set
     */
    public void setAddress(String address) {
        this.address = address;
    }

    /**
     * @return the telephone
     */
    public String getTelephone() {
        return this.telephone;
    }

    /**
     * @param telephone
     *            the telephone to set
     */
    public void setTelephone(String telephone) {
        this.telephone = telephone;
    }

    /**
     * @return the cellphone
     */
    public String getCellphone() {
        return this.cellphone;
    }

    /**
     * @param cellphone
     *            the cellphone to set
     */
    public void setCellphone(String cellphone) {
        this.cellphone = cellphone;
    }

    /**
     * @return the birth date
     */
    public Date getBirthdate() {
        return this.birthdate;
    }

    /**
     * @param birthdate
     *            the birth date to set
     */
    public void setBirthdate(Date birthdate) {
        this.birthdate = birthdate;
    }

    /**
     * @return the sex
     */
    public String getSex() {
        return this.sex;
    }

    /**
     * @param sex
     *            the sex to set
     */
    public void setSex(String sex) {
        this.sex = sex;
    }

    /**
     * @return the note
     */
    public String getNote() {
        return this.note;
    }

    /**
     * @param note
     *            the note to set
     */
    public void setNote(String note) {
        this.note = note;
    }

    /**
     *
     * @return the age of person
     */
    public Integer getAge() {
        return this.ageUtils.getAgeFromBirthDate(this.birthdate);
    }

    /**
     *
     * @return decade
     */
    public int getDecade() {
        return this.ageUtils.getDecadeFromBirthDate(birthdate);
    }

    @Override
    public String toString() {
        return this.surname + ", " + this.name;
    }

    /**
     * @param id
     *            the id to set
     */
    public void setId(Integer id) {
        this.id = id;
    }

    /**
     * @return the id
     */
    //
    public Integer getId() {
        return this.id;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return this.email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * @return the identityCard
     */
    public IdentityCard getIdentityCard() {
        return this.identityCard;
    }

    /**
     * @param identityCard the identityCard to set
     */
    public void setIdentityCard(IdentityCard identityCard) {
        this.identityCard = identityCard;
    }

    /**
     * @return the city
     */
    public String getCity() {
        return city;
    }

    /**
     * @param city the city to set
     */
    public void setCity(String city) {
        this.city = city;
    }

    /**
     * @return the lastUpdate
     */
    public Calendar getLastUpdate() {
        return lastUpdate;
    }

    /**
     * @param lastUpdate the lastUpdate to set
     */
    public void setLastUpdate(Calendar lastUpdate) {
        this.lastUpdate = lastUpdate;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((this.birthdate == null) ? 0 : this.birthdate.hashCode());
        result = prime * result + ((this.id == null) ? 0 : this.id.hashCode());
        result = prime * result + ((this.identityCard == null) ? 0 : this.identityCard.hashCode());
        return result;
    }

    /* (non-Javadoc)
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (obj == null) {
            return false;
        }
        if (!(obj instanceof Person)) {
            return false;
        }
        Person other = (Person) obj;
        if (this.birthdate == null) {
            if (other.birthdate != null) {
                return false;
            }
        } else if (!this.birthdate.equals(other.birthdate)) {
            return false;
        }
        if (this.id == null) {
            if (other.id != null) {
                return false;
            }
        } else if (!this.id.equals(other.id)) {
            return false;
        }
        if (this.identityCard == null) {
            if (other.identityCard != null) {
                return false;
            }
        } else if (!this.identityCard.equals(other.identityCard)) {
            return false;
        }
        return true;
    }
}
